package com.cgx.tablet.beeper.adapter.viewholder;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.google.gson.stream.MalformedJsonException;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


/**
 * LockDoorViewHolder 基类
 *
 * @author Created by GammaQ.
 * @version V1.0
 * @FileName: vwoof.com.xundaobaoclient.adapter.viewholder.RecycleViewHolder.java
 * @date:2016-05-07 09:51
 */
public abstract class RecycleViewHolder<M> extends RecyclerView.ViewHolder {

    public RecycleViewHolder(View itemView) {
        super(itemView);
    }

    public abstract void Bind(@NonNull M m) throws MalformedJsonException;

    /**
     * 转换日期根式
     *
     * @param dataFormat
     * @param timeStamp
     * @return
     */
    public String dateFormat(String dataFormat, long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        SimpleDateFormat format = new SimpleDateFormat(dataFormat, Locale.getDefault());
        return format.format(new Date(timeStamp));
    }

    /**
     * 默认转换日期根式
     *
     * @param timeStamp
     * @return
     */
    public String dateFormat(long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        return format.format(new Date(timeStamp));
    }

}